package com.xxyf.controller;

import com.xxyf.pojo.Usernoto;
import com.xxyf.service.NoteService;
import com.xxyf.tools.Rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @Author 小小怡飞
 * @Date 2022/9/4 8:42
 * @Version JDK 8
 */
@RestController
@Api(tags = "笔记查询")
@RequestMapping("/note")
@Slf4j
public class Note {
    @Autowired
    NoteService noteService;
    final static String SCOPE = "Note";
    @ApiOperation("查询对应用户的笔记总数")
    @GetMapping("/count/{uid}")
    private Rest count(@ApiParam("ID") @PathVariable("uid") Integer uid, HttpSession session){
        String key = (String) session.getAttribute("key");
        log.error("session"+key);
        log.error("ID"+session.getId());
        return noteService.count(uid,null);
    }
    @ApiOperation("根据分组查询")
    @GetMapping("/count/{uid}/{grouo}")
    private Rest count(@ApiParam("ID") @PathVariable("uid")Integer uid,

                       @ApiParam("分组")@PathVariable("grouo")String grouo){
        return noteService.count(uid,grouo);
    }
    @ApiOperation("查询对应内容")
    @PostMapping("/page")
    private Rest page(Integer uid, String grouo, Integer total, Integer number){
        return noteService.pageNote(uid,grouo,total,number);
    }

    @ApiOperation("添加元素")
    @PostMapping("/put")
    private Rest put(@RequestBody Usernoto noto){
       return noteService.noteput(noto);
    }
    @ApiOperation("修改元素")
    @PutMapping("/reg")
    private Rest reg(@RequestBody Usernoto noto){
        return noteService.reg(noto);
    }
    @ApiOperation("逻辑删除元素")
    @DeleteMapping("/delete")
    private Rest delect(@RequestBody Usernoto noto){
        return noteService.onedelect(noto);
    }


}
